#!/usr/bin/python
import sys
import getopt
import dnsadmin 
from dmlib import SyntaxError
from config import Config
    
def main():
    try:
        opt_list, args = getopt.getopt(sys.argv[1:], "", [
            "help",
            "zone=",
            "rid=",
            "reverse-lookup",
            "forward-lookup",
            "enabled",
            "disabled",
            "serial-number=",
            "refresh-time=",
            "retry-time=",
            "expire-time=",
            "minimum-ttl=",
            "source-host=",
            "contact-email=",
            "record-class=",
            "value=",
            "name="
        ])
        opt_dict = dict()
        for opt in opt_list:
            opt_dict[opt[0]] = opt[1]
        if "-h" in opt_dict or "--help" in opt_dict:
            print Config.HELP_INFO
            sys.exit()
        if len(args) < 1:
            raise SyntaxError, ("", True)
        else:
            comand = args[0]
            if comand == "info":
                dnsadmin.info(opt_dict, args)
            elif comand == "list":
                dnsadmin.list(opt_dict, args)
            elif comand == "add":
                dnsadmin.add_record(opt_dict, args)
            elif comand == "change":
                dnsadmin.change_record(opt_dict, args)
            elif comand == "remove":
                dnsadmin.remove_record(opt_dict, args)
            elif comand == "add-zone":
                dnsadmin.add_zone(opt_dict, args)
            elif comand == "remove-zone":
                dnsadmin.remove_zone(opt_dict, args)
            elif comand == "change-zone":
                dnsadmin.change_zone(opt_dict, args)
            elif comand == "sync":
                dnsadmin.sync(opt_dict, args)
            else:
                raise SyntaxError, (Config.MESSAGE["2"], True)
    except getopt.GetoptError, err:
        print err
        print Config.HELP_INFO
        sys.exit(2)
    except SyntaxError, data:
        print data[0]
        if data[1:2] and data[1] == True:
            print Config.HELP_INFO
        sys.exit(2)
    """
    except:
        print Config.MESSAGE["4"]
        sys.exit(2)
    """

if __name__ == "__main__":
    main()